package com.nuist.springmvcdemo.Controller;

import com.nuist.springmvcdemo.model.messageInfo;
import com.nuist.springmvcdemo.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageController {
    @Autowired
    private MessageService messageService;

    @RequestMapping("/getList")
    private List<messageInfo> getList() {
        return messageService.getMessageList();
    }

    @RequestMapping("/publish")
    public boolean publish(messageInfo messageInfo) {
        // 这是把留言墙的信息上传到后端服务
        if (StringUtils.hasLength(messageInfo.getFrom()) && StringUtils.hasLength(messageInfo.getTo()) && StringUtils.hasLength(messageInfo.getMessage())) {
            Integer result = messageService.publishMessage(messageInfo);
            if (result > 0) {
                return true;
            }
        }
        return false;
    }
}
